<template>
	<view class="box">
		<view class="">
			<!-- 			<u-navbar title="消息" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
								leftIconColor="#333" titleStyle="color:#333" bgColor="transparent"></u-navbar> -->

			<u-navbar title="更多" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#666" titleStyle="color:#333" bgColor="transparent" @leftClick="leftClick"></u-navbar>
			<image class="indexbg"
				src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
				mode="aspectFill"></image>
		</view>


		<view class="main">
			<view class="item">
				<image :src="info.avatar" mode="aspectFill"></image>
				<text>{{info.nickname}}</text>
				<view class="tag" v-if="info.is_admin==1">
					群主
				</view>
				<view class="tag" v-if="info.is_admin==2">
					管理员
				</view>

			</view>

		</view>
		<view class="wrap" >
			<text>设置管理员</text>
			<u-switch v-model="isflag" @change="changestatus" activeColor="#FFC300"
				inactiveColor="rgb(230, 230, 230)"></u-switch>
		</view>
		<view class="wrap" v-if="info.is_admin==0">
			<text>禁言该成员</text>
			<u-switch v-model="isflag2" @change="changestatus2" activeColor="#FFC300"
				inactiveColor="rgb(230, 230, 230)"></u-switch>
		</view>
		<view style="width: 750rpx;height: 88rpx;">

		</view>
	</view>
</template>

<script>
	import {
		groupMemberDetails,
		groupDetails,
		setAdministrator,
		blockUserSendMsg,
		unblockUserSendMsg
	} from "../../api/hx.js"
	export default {
		data() {
			return {
				info: {},
				isflag: false,
				isflag2: false,
				groupid: "",
				is_admin: ""
			}
		},
		onLoad(option) {
			this.info = uni.getStorageSync("groupitem")
			if (this.info.is_admin == 2) {
				this.isflag = true
			}
			if (this.info.is_admin == 0) {
				this.isflag = false
			}
			if (this.info.is_forbidden_speech == 1) {
				this.isflag2 = true
			}
			if (this.info.is_forbidden_speech == 0) {
				this.isflag2 = false
			}
			this.groupid = option.id
			console.log(this.info)
		},
		onShow() {

		},
		methods: {
			set() {
				console.log(this.is_admin)
				setAdministrator({
					hx_group_id: this.groupid,
					is_admin: this.is_admin,
					admin_user_id: this.info.user_id
				}).then(res => {
					setTimeout(()=>{
						uni.redirectTo({
							url:"/pageDao/groupchat/groupnum?id="+this.groupid
						})
					},1000)
					
					uni.$u.toast(res.msg)
				})
			},
			unmute() {
				unblockUserSendMsg({
					hx_group_id: this.groupid,
					user_ids: this.info.user_id
				}).then(res => {
					setTimeout(()=>{
						uni.redirectTo({
							url:"/pageDao/groupchat/groupnum?id="+this.groupid
						})
					},1000)
					uni.$u.toast(res.msg)

				})
			},
			mute() {
				blockUserSendMsg({
					hx_group_id: this.groupid,
					user_ids: this.info.user_id
				}).then(res => {
						setTimeout(()=>{
											uni.redirectTo({
												url:"/pageDao/groupchat/groupnum?id="+this.groupid
											})
										},1000)
					uni.$u.toast(res.msg)
				})
			},
			changestatus2(e) {
				if (e == true) {
					this.mute()
				}
				if (e == false) {
					this.unmute()
				}
			},
			changestatus(e) {
				console.log(e)
				if (e == true) {
					this.is_admin = "2"
					this.set()
				}
				if (e == false) {
					this.is_admin = "0"
					this.set()
				}
				console.log(this.is_admin)
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
		}
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="scss">
	.box {
		width: 750rpx;

	}

	/deep/.u-navbar__content {
		background: transparent;
	}

	.indexbg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 460rpx;

	}

	/deep/ .u-navbar__content__right__text {
		color: #FF1616;
	}

	.wrap_top {
		width: 750rpx;
	}

	.search {
		width: 690rpx;
		height: 72rpx;
		background: #342857;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 0 auto;
		position: relative;

		>image {
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;

		}

		>input {
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: rgba(255, 255, 255, 0.8);
		}
	}

	.main {
		width: 750rpx;

	}

	.item {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;

		>image {
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}

		>text {
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 15rpx;
			max-width: 300rpx;
			white-space: nowrap;
			/* 防止文本换行 */
			overflow: hidden;
			/* 隐藏溢出的文本 */
			text-overflow: ellipsis;
			/* 当文本溢出时显示省略号 */
		}

		.tag {
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: #FFC300;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: #fff;
			text-align: center;
			margin-left: 20rpx;
		}

	}

	/deep/.uni-checkbox-input {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		right: 40rpx;
		border-radius: 50%;
	}

	.wrap {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 40rpx;
		display: flex;
		align-items: center;
		height: 80rpx;
		justify-content: space-between;

		>text {
			font-weight: 400;
			font-size: 32rpx;
			color: #333;
		}
	}
</style>